import { Component, Input, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { NzModalService } from 'ng-zorro-antd/modal';
import { appConfig } from 'src/app/config/app-config';
import { LoginService } from 'src/app/service/login.service';
import { UserInfoData, UserInfoService } from 'src/app/service/user-info/user-info.service';

@Component({
  selector: 'app-the-header',
  templateUrl: './the-header.component.html',
  styleUrls: ['./the-header.component.scss']
})
export class TheHeaderComponent implements OnInit {

  constructor(
    private router: Router,
    private userInfoService: UserInfoService,
    private loginService: LoginService,
    private modal: NzModalService
  ) { }


  darkLogo = appConfig.LOGO_BLACK
  writeLogo = appConfig.LOGO

  userIcon1 = 'assets/images/icons/user.svg'
  userIcon2 = 'assets/images/icons/user2.svg'
  logoutIcon1 = 'assets/images/icons/logout.svg'
  logoutIcon2 = 'assets/images/icons/logout2.svg'

  @Input() isHome = true
  ngOnInit(): void {
    this.pageInit()
  }

  goHome(){
    this.router.navigate(['/home'])
  }

  userInfo: UserInfoData | null = null
  pageInit(){
    this.userInfo = this.userInfoService.getUserInfo()
  }

  goLoginPage(){
    this.router.navigate(['/login'])
  }
  goMe(){
    this.router.navigate(['/me'])
  }

  logout(){
    this.modal.confirm({
      nzTitle: '<i>确认退出吗 ?</i>',
      nzContent: '<b>退出后部分业务不可办理 !</b>',
      nzOnOk: () => {
        this.userInfoService.clearUser()
        this.userInfo = null
        this.router.navigate(['/home'])
        this.loginService._logout().subscribe({
          next: () => {
            
          },
        })
      }
    })

    
  }

}
